package com.zej.dao;

import com.zej.bean.Employee;

import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author 一缕茜阳
 * @date 2021/11/6
 */
@Repository
public class EmployeeDao {
    private static Map<Integer, Employee> employees = null;

    static {
        employees = new HashMap<>();
        employees.put(1001, new Employee(1001, "A01", "001@email", 0, 101));
        employees.put(1002, new Employee(1002, "A02", "002@email", 1, 102));
        employees.put(1003, new Employee(1003, "A03", "003@email", 1, 102));
        employees.put(1004, new Employee(1004, "A04", "004@email", 0, 103));
        employees.put(1005, new Employee(1005, "A05", "005@email", 1, 104));
        employees.put(1006, new Employee(1006, "A06", "006@email", 0, 101));

    }

    private static Integer initId = 1007;

    public void addEmployee(Employee employee) {
        if (Objects.isNull(employee.getId())) {
            employee.setId(initId++);
        }
        employees.put(employee.getId(), employee);
    }

    public Collection getAllEmployee() {
        return employees.values();
    }

    public Employee getEmployeeById(Integer id) {
        return employees.get(id);
    }

    public Employee removeEmployee(Employee employee) {
        return employees.remove(employee.getId());
    }
}
